<template>
    <div>
        <h2>病房信息添加</h2>
        <input type="button" value="添加医生" @click="addys">
        <br>
        <table class="table">
            <tbody>
                <tr>
                    <td>病房号</td>
                    <td>
                        <input v-model="data.name" type="text">
                    </td>
                </tr>
                <tr>
                    <td>所属科室</td>
                    <td>
                        <select v-model="data.kname" name="" id="">
                            <option value="">请选择</option>
                            <option value="内科">内科</option>
                            <option value="外科">外科</option>
                            <option value="心脑科">心脑科</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>床位数</td>
                    <td>
                        <input v-model="data.num" type="text">
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input v-model="data.state" type="radio" name="1" id="" checked :value="true">启用
                        <input v-model="data.state" type="radio" name="1" id=""  :value="false">维修
                    </td>
                </tr>
                <tr>
                    <td>空床位</td>
                    <td>
                        <input v-model="data.knum" type="text">
                    </td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td>
                        <input type="date" name="" id="" v-model="data.startdate">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();

const data=ref({
  "id": 0,
  "name": "",
  "kname": "",
  "num": 0,
  "state": true,
  "knum": 0,
  "startdate": "",
  "enddate": "2025-02-18T08:09:46.040Z"
})
const add=()=>{
    if(confirm('确认添加吗？'))
    if(data.value.name==""){
        alert('病房号不能为空');
        return;
    }
    if(data.value.name.length>6){
        alert('病房号不能超过6个字符');
        return;
    }
    
    axios.post('https://localhost:7260/api/BingFang/AddBingFang',data.value).then(res=>{
        if(res.data>0){
            alert('添加成功');
            router.push('/showbf')
            return;
        }
        if(res.data==-1){
            alert('病房号已存在');
            return
        }
        else{
            alert('失败');
        }
    })
}
const addys=()=>{
    router.push('/addys')
}
</script>

<style scoped>

</style>